<template>
  <el-dialog title="提前转出审核" :visible.sync="isShow" @close="$emit('update:isShowAudit', false)" width="500px" :close-on-click-modal="false">
    <el-form label-position="right" ref="info" :rules="rules" :model="info" label-width="120px">
      <el-form-item class="noValidate" label="供应商企业名称:">
        <span>{{info.enterpriseName}}</span>
      </el-form-item>
      <el-form-item class="noValidate" label="提前转出总额:">
        <span>{{info.amount}}</span>
      </el-form-item>
      <el-form-item class="noValidate" label="提前转出保理费:">
        <span>{{info.facAmount}}</span>
      </el-form-item>
      <el-form-item class="noValidate" label="申请转出时间:">
        <span>{{info.applyTime}}</span>
      </el-form-item>
      <el-form-item label="审核结果:" prop="status">
        <el-radio v-model="info.status" :label="1">审核通过</el-radio>
        <el-radio v-model="info.status" :label="2">驳回审核</el-radio>
      </el-form-item>
      <el-form-item label="审核备注:" prop="reason">
        <el-input type="textarea" v-model="info.reason"
                  :autosize="{ minRows: 3, maxRows: 5}"></el-input>
      </el-form-item>
      <p class="c-gray">备注：请务必填写审核备注内容,一旦审核通过，转出金额将扣除手续费后转入至供应商余额账户内</p>
    </el-form>
    <div class="footer text-center mt20">
      <el-button @click="isShow = false">取 消</el-button>
      <el-button type="primary" @click="onSubmit('info')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: "TransferOutAudit",
    props: {
      isShowAudit: {
        type: Boolean,
        default: false
      },
      auditInfo: {
        type: Object,
        default: () => {
          return {
            id: null,
            enterpriseName: "",
            amount: "",
            facAmount: "",
            applyTime: ""
          }
        }
      }
    },
    data() {
      return {
        isShow: this.isShowAudit,
        info: {...this.auditInfo, status: 1, reason: ""},
        rules: {
          status: [{required: true, message: '请选择审核状态', trigger: 'blur'}],
          reason: [
            {required: true, message: '请输入审核备注', trigger: 'blur'},
            {validator: validate.length150, trigger: 'change'}
          ]
        }
      }
    },
    watch: {
      isShowAudit(val) {
        this.isShow = val
      },
      auditInfo(val) {
        this.info = {...val, status: 1, reason: ""}
      }
    },
    methods: {
      onSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.updateAudit()
          }
          else {
            return false;
          }
        });
      },
      updateAudit() {
        ajax.post(apis.factory.auditApply, {id: this.info.id, reason: this.info.reason, status: this.info.status})
          .then(res => {
            if (res.success === true) {
              this.$message({
                message: res.message,
                type: 'success'
              });
              this.isShow = false
              this.$emit("refreshCurrentPage")
            } else {
              this.$message({
                message: res.message,
                type: 'error'
              })
            }
          })
      }
    },
    created() {
    }
  }
</script>

<style lang="scss" scoped>
  .noValidate {
    margin: 0;
  }
</style>
